﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using System.Data;
using System.IO;
using System.Windows.Forms;

namespace SyncLib.Provider
{
    public class UpdateProvider : BaseKeeperSync
    {
        static ILog Log = LogManager.GetLogger(typeof(Log4NetImplement));
        protected override void OnSyncProgress(Microsoft.Synchronization.Data.DbSyncProgressEventArgs e)
        {
            try
            {
                DataRow row = e.TableProgress.DataTable.Rows[e.TableProgress.RowIndex];
                Byte[] data = ProxyInfo.Channel.GetApplicationResource(row["FilePath"].ToString(), row["FileType"].ToString());
                File.WriteAllBytes(Path.Combine(Application.StartupPath + "\\Update\\", row["FilePath"].ToString()), data);
                if (e.TableProgress.RowIndex == (e.TableProgress.DataTable.Rows.Count - 1))
                {
                    e.TableProgress.DataTable.WriteXml(Application.StartupPath + "\\Update\\Update.xml");
                }
                base.OnSyncProgress(e);
            }
            catch (Exception ex)
            {
                Log.Fatal(GetType().FullName + " OnSyncProgress Exception ", ex);
                throw ex;
            }
        }
    }
}
